package com.dcbeida.adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.dcbeida.R;
import com.dcbeida.bean.Customer;
import com.dcbeida.bean.Sales;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * 销售
 */
public class AccountListAdapter extends BaseAdapter {

    private ArrayList<Customer> mArrayList = new ArrayList<>();
    private Context mContext;

    public AccountListAdapter(Context context) {
        super();
        this.mContext = context;
    }


    @Override
    public int getCount() {
        if (mArrayList == null) {
            return 0;
        } else {
            return this.mArrayList.size();
        }
    }

    @Override
    public Object getItem(int position) {
        if (mArrayList == null) {
            return null;
        } else {
            return this.mArrayList.get(position);
        }
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.account_item, parent, false);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        Customer bean = mArrayList.get(position);
        holder.tvHeader.setText(bean.getName());
        holder.tvName.setText(bean.getName());
        holder.tvName.setTextColor(mContext.getResources().getColor(R.color.c_222222));
        holder.tvTel.setText(bean.getMobile());
        holder.tvTel.setTextColor(mContext.getResources().getColor(R.color.c_444444));
        holder.tvAddTime.setText(bean.getCreateTime()+" 添加");
        holder.tvAddTime.setTextColor(mContext.getResources().getColor(R.color.c_999999));
        if("男".equals(bean.getGender())){
            holder.tvHeader.setBackgroundResource(R.drawable.shape_boy);
        }else {
            holder.tvHeader.setBackgroundResource(R.drawable.shape_girl);
        }
        if(bean.getStatus() ==1){
            holder.tvStatus.setText("已启用");
            holder.tvStatus.setTextColor(mContext.getResources().getColor(R.color.c_3CAF5C));
        }else {
            if(bean.getAuditStatus()==0){//待审核
                holder.tvStatus.setText("待审核");
                holder.tvStatus.setTextColor(mContext.getResources().getColor(R.color.c_EB3030));
            }else  if(bean.getAuditStatus()==2){
                holder.tvStatus.setText("审核未通过");
                holder.tvStatus.setTextColor(mContext.getResources().getColor(R.color.c_EB3030));
            }else {
                holder.tvAddTime.setTextColor(mContext.getResources().getColor(R.color.c_CCCCCC));
                holder.tvTel.setTextColor(mContext.getResources().getColor(R.color.c_CCCCCC));
                holder.tvHeader.setBackgroundResource(R.drawable.shape_jy);
                holder.tvStatus.setText("已禁用");
                holder.tvStatus.setTextColor(mContext.getResources().getColor(R.color.c_999999));
                holder.tvName.setTextColor(mContext.getResources().getColor(R.color.c_CCCCCC));
            }
        }

//        if(position ==mArrayList.size()-1){
//            holder.v_line.setVisibility(View.GONE);
//        }else {
//            holder.v_line.setVisibility(View.VISIBLE);
//        }

        return convertView;
    }


    public ArrayList<Customer> getmArrayList() {
        return mArrayList;
    }

    public void setmArrayList(List<Customer> mArrayList) {
        if (mArrayList.size() >= 0) {
            this.mArrayList.addAll(mArrayList);
        }
        notifyDataSetChanged();
    }

    public void clearList() {
        this.mArrayList.clear();
    }


    class ViewHolder {
        @Bind(R.id.tv_header)
        TextView tvHeader;
        @Bind(R.id.tv_name)
        TextView tvName;
        @Bind(R.id.tv_tel)
        TextView tvTel;
        @Bind(R.id.tv_add_time)
        TextView tvAddTime;
        @Bind(R.id.tv_status)
        TextView tvStatus;
        @Bind(R.id.v_line)
        View v_line;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
